package com.wingice.business.controller;


import com.wingice.business.entity.VisitSysMenu;
import com.wingice.business.service.VisitSysMenuService;
import com.wingice.log.annotation.OperationLog;
import com.wingice.msg.ali.service.KnifeSmsAliService;
import com.wingice.msg.mail.service.KnifeMailService;
import com.wingice.msg.wechat.mp.service.KnifeWechatMpMsgService;
import com.wingice.msg.wechat.mp.vo.WechatMpTemplateData;
import com.wingice.msg.wechat.mp.vo.WechatMpTemplateMessage;
import com.wingice.spring.security.annotation.Inner;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 菜单信息 前端控制器
 * </p>
 *
 * @author 胡昊
 * @since 2021-01-08
 */
@RestController
@RequestMapping("/visitSysMenu")
public class VisitSysMenuController {

    @Resource
    private VisitSysMenuService visitSysMenuService;
    @Resource
    private KnifeMailService knifeMailService;
    @Resource
    private KnifeSmsAliService knifeSmsAliService;
    @Resource
    private KnifeWechatMpMsgService knifeWechatMpMsgService;

    @PreAuthorize("@knifeSecurity.hasPermission('sss')")
    @GetMapping("/test")
    public Object test() {
        return visitSysMenuService.list();
    }

    @Inner
    @PostMapping("/test2")
    public Object test2(@RequestBody VisitSysMenu visitSysMenu) {
        return visitSysMenuService.updateById(visitSysMenu);
    }

    @OperationLog(operationModule = "test", operationDesc = "这个是用于测试的方法", operationType = "add")
    @GetMapping("/test3")
    public Object test3(String param) {
        return param;
    }


    //    @OperationLog(operationModule = "test", operationDesc = "这个是用于测试的方法" ,operationType = "delete" )
    @GetMapping("/test4")
    public Object test4(String param) {
//        MailInfo mailInfo = new MailInfo();
//        mailInfo.setTo("1120023921@qq.com");
//        mailInfo.setSubject("333");
//        mailInfo.setText("etetewtewtwe");
//        return knifeMailService.sendMail(mailInfo);

//        AliSms aliSms = new AliSms();
//        aliSms.setSignName("浙江wingice软件");
//        aliSms.setPhoneNumbers("17857026467");
//        aliSms.setTemplateCode("SMS_186625014");
//        aliSms.setTemplateParam("{\"code\":\"10001\"}");
//        return knifeSmsAliService.sendSms(aliSms);

        List<WechatMpTemplateData> wechatMpTemplateDataList = new ArrayList<>();

        WechatMpTemplateData first = new WechatMpTemplateData();
        first.setName("first");
        first.setValue("测试通知");
        wechatMpTemplateDataList.add(first);

        WechatMpTemplateData keyword1 = new WechatMpTemplateData();
        keyword1.setName("keyword1");
        keyword1.setValue("测试通知keyword1");
        wechatMpTemplateDataList.add(keyword1);

        WechatMpTemplateData keyword2 = new WechatMpTemplateData();
        keyword2.setName("keyword2");
        keyword2.setValue("测试通知keyword2");
        wechatMpTemplateDataList.add(keyword2);

        WechatMpTemplateData keyword3 = new WechatMpTemplateData();
        keyword3.setName("keyword3");
        keyword3.setValue("测试通知keyword3");
        wechatMpTemplateDataList.add(keyword3);

        WechatMpTemplateData keyword4 = new WechatMpTemplateData();
        keyword4.setName("keyword4");
        keyword4.setValue("测试通知keyword4");
        wechatMpTemplateDataList.add(keyword4);

        WechatMpTemplateData remark = new WechatMpTemplateData();
        remark.setName("remark");
        remark.setValue("测试通知remark");
        wechatMpTemplateDataList.add(remark);

        return knifeWechatMpMsgService.sendWechatMpTemplateMessage(WechatMpTemplateMessage.builder()
                .msgId("1")
                .toUser("oJrcXv7xX_W81lvxL2p2pv7DuYJM")
                .templateId("6IyZeJJXftqV0Cd5kaj9KM1x0ZOuAJUbtLsFlUYiWO4")
                .data(wechatMpTemplateDataList)
                .build());
//        return null;
    }
}

